package com.yyge.controller.admin.dashboard.strategy;

import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateUtil;
import com.yyge.controller.admin.dashboard.resp.ReportResp;
import com.yyge.service.ContamerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;

/**
 * @Author wy
 * @Description 本年
 * @Date 2023/7/17 10:29
 * @Version 1.0
 */
@Component
public class CurrentYearReport implements ContamerReportStrategy {

    @Autowired
    private ContamerService contamerService;


    @Override
    public ReportResp calcReport() {
        int year = DateUtil.date().getField(DateField.YEAR);
        //数据库查询结果
        List<Map> mapList = null;
                //this.contamerService.currentReportYear(year);

        List<String> xAxis=new ArrayList<>();
        List<Object> series=new ArrayList<>();

        for(int i=1;i<=12;i++){
            xAxis.add(i+"月");
            Optional<Map> optionalMap = mapList.stream().filter(m -> m.get("yue") != null).findFirst();
            //查询到了
            if(optionalMap.isPresent()){
               Object value=optionalMap.get().get("num");
               series.add(value==null?0:value);
            }else{
                series.add(0);
            }
        }

        ReportResp  reportResp=new ReportResp();
        reportResp.setXAxis(xAxis);
        reportResp.setSeries(series);
        return reportResp;
    }
}